from time import sleep

import allure

from common.airtest.airtest_base import AirtestBase
from common.log.log import log
from config.conf import BASE_DIR


class SearchPage:
    """
    搜索页面
    """

    @allure.step('输入搜索词进行搜索')
    def search_keyword(self, keyword):
        """
        输入搜索词进行搜索
        """
        try:
            AirtestBase().click_5_input(keyword, BASE_DIR + r"/element_picture/搜索结果页/搜索输入框.png")
            AirtestBase().click_5(BASE_DIR + r"/element_picture/搜索结果页/搜索按钮.png")
            sleep(2)
            return SearchPage()
        except Exception as e:
            log.error(f'搜索过程中出现异常为：{e}')
            raise e
